using System;
using System.Net.Sockets;

namespace Fadd.Net
{
    /// <summary>
    /// Used to transport objects from one process to another.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IObjectTransport<T> where T : new()
    {
        /// <summary>
        /// Gets if socket is connected.
        /// </summary>
        bool IsConnected { get; }

        /// <summary>
        /// Send an object.
        /// </summary>
        /// <param name="value">Object to send</param>
        /// <remarks>
        /// Must be marked as serializable and connection must be open.
        /// </remarks>
        void Send(T value);

        /// <summary>
        /// Start waiting for incoming packets.
        /// </summary>
        /// <param name="socket">Connected socket</param>
        /// <remarks>
        /// Will use the socket for communication. Socket is from
        /// now on owned by this class. Do not attempt to use it on your own.
        /// </remarks>
        void Start(Socket socket);

        /// <summary>
        /// Received a packet from remote end point.
        /// </summary>
        event EventHandler<ObjectEventArgs<T>> ObjectReceived;

        /// <summary>
        /// Client side disconnected.
        /// </summary>
        event EventHandler Disconnected;

        /// <summary>
        /// Connected to remote end point.
        /// </summary>
        event EventHandler Connected;

        /// <summary>
        /// Start waiting for incoming packets.
        /// </summary>
        void Start();
    }
}